<div class="navigation">
    <a href="/">Главная</a>&nbsp;&nbsp;/&nbsp;&nbsp;<a href="<?= Yii::app()->controller->createUrl('/profile/tariff_plans'); ?>" class="nav_active">Мои Тарифы</a>
</div>
<div>
    <h1 class="zag">Мои Тарифы</h1>
    <div class="line"> </div>
<br /><br />

<?php if ( Yii::app()->user->hasFlash('profile_tariff_plans') ) : ?>
<br />
<div class="success">
    <?= Yii::app()->user->getFlash('profile_tariff_plans'); ?>
</div>
<br />
<?php endif; ?>

<table class="navigator">
	<tr class="header">
                <td align="center">#</td>
		<td align="center">ТП</td>
		<td align="center">Кол-во заявок</td>
		<td align="center">Осталось заявок</td>
		<td align="center"><?= $aTariffPlansLabels['date_created'];?></td>
		<td align="center"><?= $aTariffPlansLabels['date_start'];?></td>
		<td align="center"><?= $aTariffPlansLabels['date_expired'];?></td>
		<td align="center">Статус</td>
                <td align="center"></td>
	</tr>
	<?php foreach ($aTariffPlans as $aTariffPlanItem):?>
	<tr class="row-tr">
		<td align="center">#<?= $aTariffPlanItem->tariff_plan_id;?></td>
		<td align="center"><?= $aTariffPlanItem->name;?></td>
		<td align="center"><?= $aTariffPlanItem->lots_count;?></td>
		<td align="center"><?= $aTariffPlanItem->lots_left;?></td>
                <td align="center"><?= date('d-m-Y H:i', strtotime($aTariffPlanItem->date_created));?></td>
		<td align="center"><?= $aTariffPlanItem->date_start?date('d-m-Y H:i', strtotime($aTariffPlanItem->date_start)):'';?></td>
		<td align="center"><?= $aTariffPlanItem->date_expired?date('d-m-Y H:i', strtotime($aTariffPlanItem->date_expired)):'';?></td>
		
		<?php if(strtotime('-30 day') > strtotime($aTariffPlanItem->date_created)):?>
			<td align="center">Окончен</td>
                        <td align="center"></td>
		<?php elseif($aTariffPlanItem->status == 'approved'):?>

                        <?php if($aTariffPlanItem->tariff_plan == TariffPlan::PLAN_METALS || intval($aTariffPlanItem->lots_left) > 0):?>
                            <td align="center">Активен</td>
                        <?php else:?>
                            <td align="center">Заявки закончились</td>
                        <?php endif;?>
                            
			<?php if($aTariffPlanItem->tariff_plan != TariffPlan::PLAN_START && $aTariffPlanItem->tariff_plan != TariffPlan::PLAN_METALS):?>
				<td align="center"><a href="<?= Yii::app()->controller->createUrl('/profile/tariff_plans/buy_lot', array('tariff_plan_id' => $aTariffPlanItem->tariff_plan_id)); ?>">Купить 1 заявку</a></td>
			<?php else:?>
				<td align="center"></td>
			<?php endif;?>
                <?php elseif($aTariffPlanItem->status == 'rejected'):?>
                       <td align="center">Заявка отклонена</td>
                       <td align="center"></td>
		<?php else:?>
			<td align="center">На рассмотрении</td>
                        <td align="center"></td>
		<?php endif;?>
	</tr>
	<?php endforeach;?>
</table>
<br />
<a href="<?= Yii::app()->controller->createUrl('/profile/tariff_plans/add'); ?>">Добавить Тарифный План</a>
</div>